#include "page.h"
//#include "page_manager.h"
#include "start_up.h"
#include "dialplate.h"


#define APP_CLASS_MATCH(NAME)           \
    do                                  \
    {                                   \
        if (strcmp(name, #NAME) == 0)   \
        {                               \
            return NAME##_create(name); \
        }                               \
    } while (0)


static page_manager_t *s_manager = NULL;

void page_init(void)
{
    s_manager = page_manager_create();
    pm_set_global_load_anim_type(s_manager, LOAD_ANIM_OVER_TOP, 500, lv_anim_path_overshoot);
}

page_vtable_t *_page_create(const char *name)
{
    APP_CLASS_MATCH(startup);
		APP_CLASS_MATCH(dialplate);
    return NULL;
}

void page_install(const char *name)
{
    page_vtable_t* page = _page_create(name);
    if (page != NULL)
    {
        pm_install(s_manager, name, page);
    }
    else
    {
        //ESP_LOGI(tag, "page not exist");
    }
}

void page_start(const char *name)
{
    pm_push(s_manager, name, NULL);
}

void page_pop(void)
{
    pm_pop(s_manager);
}


void default_style(void)
{
  /* Set screen style */
    lv_obj_t* scr = lv_scr_act();
    lv_obj_remove_style_all(scr);
    lv_obj_set_style_bg_opa(lv_scr_act(), LV_OPA_COVER, 0);
    lv_obj_set_style_bg_color(lv_scr_act(), lv_color_black(), 0);
    lv_obj_clear_flag(scr, LV_OBJ_FLAG_SCROLLABLE);
    lv_disp_set_bg_color(lv_disp_get_default(), lv_color_black());
	  //lv_obj_set_style_border_color(scr, lv_color_black(), 0);
    //lv_obj_set_style_border_side(scr, LV_BORDER_SIDE_FULL, 0);
    //lv_obj_set_style_border_width(scr, 10, 0);

    /* Set root default style */
    static lv_style_t rootStyle;
    lv_style_init(&rootStyle);
    lv_style_set_width(&rootStyle, LV_HOR_RES);
    lv_style_set_height(&rootStyle, LV_VER_RES);
    lv_style_set_bg_opa(&rootStyle, LV_OPA_COVER);
    lv_style_set_bg_color(&rootStyle, lv_color_black());
	  pm_set_root_default_style(s_manager, &rootStyle);
}

#if 0
void lvgl_resource_init(void)
{
	 /* Import Images */
		IMPORT_IMG(alarm);
		IMPORT_IMG(battery);
		IMPORT_IMG(battery_info);
		IMPORT_IMG(bicycle);
		IMPORT_IMG(compass);
		IMPORT_IMG(gps_arrow_default);
		IMPORT_IMG(gps_arrow_dark);
		IMPORT_IMG(gps_arrow_light);
		IMPORT_IMG(gyroscope);
		IMPORT_IMG(locate);
		IMPORT_IMG(map_location);
		IMPORT_IMG(menu);
		IMPORT_IMG(origin_point);
		IMPORT_IMG(pause);
		IMPORT_IMG(satellite);
		IMPORT_IMG(sd_card);
		IMPORT_IMG(start);
		IMPORT_IMG(stop);
		IMPORT_IMG(storage);
		IMPORT_IMG(system_info);
		IMPORT_IMG(time_info);
		IMPORT_IMG(trip);
}
#endif
